home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / game / role / World.lha / source / helper.c < prev    next >
C/C++ Source or Header  |  2001-03-06  |  27KB  |  1,188 lines

  1. #include <stdio.h>
  2. #include "parame.inc"
  3. #include "variab.h"
  4. #include "arrays.h"
  5. #include "qtext.inc"
  6. #define abs(A) ((A < 0) ? -A : A)
  7.  
  8. #ifndef AMIGA
  9. #  define Q1TEXT    "/usr/games/lib/q1text.dat"
  10. #endif
  11.  
  12. /* World C Version 1.00 copyright 1987 J.D.McDonald 
  13.    Use as you like for non-commercial purposes, but please
  14.    leave this note, and document any changes you make as yours */
  15.  
  16. static int      start = 0;
  17. int             q1text_dat;
  18. static int      debugflg = 1;
  19. static char     filenm[] = "world.sav";
  20.  
  21. static short    buffer[512];
  22. static long     filepos, oldpos;
  23.      
  24.  
  25. speak(point)
  26.     int             point;
  27. {
  28.     /* 
  29.      * this is the main routine to output text from the data file the word
  30.      * rtext(point) points to the proper record in the file  
  31.      */
  32.     int             i, bi, t, kk;
  33.     long            z;
  34.  
  35.     if (start == 0) {
  36.     start += 1;
  37.     oldpos = -1;
  38. #ifndef AMIGA                     /* q1text.dat already opened in wbstuff.c */
  39.     q1text_dat = open(Q1TEXT, 0);
  40. #endif
  41.       
  42.     }
  43.     z = (long) ((unsigned long) rtext[point]);
  44.     filepos = z * 2 & ~1023l;
  45.     if (filepos != oldpos) {
  46.     oldpos = filepos;
  47.     lseek(q1text_dat, filepos, 0);
  48.     read(q1text_dat, buffer, 512*sizeof(short));
  49.     }
  50.     bi = z & 511;
  51.     do {
  52.     kk = 0;
  53.     while (1) {
  54.         if (bi == 512) {
  55.         oldpos += 1024;
  56.         lseek(q1text_dat, oldpos, 0);
  57.         read(q1text_dat, buffer, 512*sizeof(short));
  58.         bi = 0;
  59.         }
  60.         t = buffer[bi];
  61.             z++;
  62.             bi++;
  63.  
  64.         if (t < 0) {
  65.         t = -t;
  66.         outst2[kk++] = t & 127;
  67.         outst2[kk++] = t >> 8;
  68.         } else {
  69.         outst2[kk++] = (t % 32) + 96;
  70.         outst2[kk++] = ((t >> 5) % 32) + 96;
  71.         outst2[kk++] = t / 1024 + 96;
  72.         if (outst2[kk - 3] == '{') {
  73.             kmax = kk - 4;
  74.                 break;
  75.         } 
  76.         }
  77.         if (outst2[kk - 2] == '{') {
  78.                 kmax = kk - 3;
  79.         break;
  80.         } else if (outst2[kk - 1] == '{') {
  81.             kmax = kk - 2;
  82.         break;
  83.         }
  84.     }
  85.     for (i = 0; i <= kmax; i++) {
  86.         if (outst2[i] == '`')
  87.         outst2[i] = ' ';
  88.         if (outst2[i] == '|')
  89.         outst2[i] = '.';
  90.     }
  91.     if (wwflag == 0)
  92.         linout(outst2, kmax + 1);
  93.     } while (z < rtext[point + 1]);
  94. }
  95.  
  96. vlocat(i, h)
  97.     int             i, h;
  98. {
  99.     int             k, p, r, nowir, xloc, xturn;
  100.     /*
  101.      * code for "l" or "locate"  but NOT "look" gtext(2) points to short
  102.      * descriptions in the location area of the text file, while gtext(1)
  103.      * points to the long ones  
  104.      */
  105.  
  106.     if (brfflg == 2 || i == 1 || ((locdat[loc] & 16384) == 0
  107.                   && brfflg != 0) || (loc >= 101 && loc <= 116))
  108.     xloc = loc + gtext[1];
  109.     else
  110.     xloc = loc + gtext[2];
  111.     speak(xloc);
  112.     if (loc == 89) {
  113.     if (easttm == 0) {
  114.         speak(372);
  115.         eastsc |= 1;
  116.     } else if (easttm > 0 && easttm <= 50) {
  117.         speak(373);
  118.         eastsc |= 2;
  119.     } else if (easttm == 51)
  120.         speak(374);
  121.     else {
  122.         speak(375);
  123.         eastsc |= 4;
  124.     }
  125.     }
  126.     xturn = turns % 100;
  127.     if (turns < 8)
  128.     xturn = 8;
  129.     if (h == 0)
  130.     return;
  131.     /* this section prints out the objects at "loc"  */
  132.     for (k = 1; k <= OBJMAX; k++) {
  133.     p = obimpr[k];
  134.     if (!((k <= MOVMAX && obloc[k] != loc) ||
  135.           (k > MOVMAX && (obw3[k] != loc && obw4[k] != loc)) ||
  136.           (k == HPUCK && loc == 38 && marflg[1]))) {
  137.         r = (p / 8) % 8;
  138.         if (r >= 1) {
  139.         if ((p & 1) == 1)
  140.             speak(odistb[k] + r);
  141.         }
  142.         if (!(obpprp[k] / 2048 == 0 && k != ZROBOT))
  143.         xcontn(k);
  144.     } continue;
  145.     }
  146.     /* standing on something?  */
  147.     if (spcloc == 1)
  148.     speak(212);
  149.     if (spcloc == 2) {
  150.     if (dirty == 0)
  151.         speak(509);
  152.     else
  153.         speak(510);
  154.     }
  155.     /* is the wire lying on the ground */
  156.     nowir = 1;
  157.     for (i = 0; i < 6; i++) {
  158.     if (wirelc[i] == loc)
  159.         nowir = 0;
  160.     }
  161.     if (nowir == 0)
  162.     speak(215);
  163.  
  164.     if ((loc == 76 || loc == 77 || loc == 79) && obloc[ZCAT] ==
  165.     80)
  166.     speak(280);
  167.     /* flowers following sun  */
  168.     if (loc == 86 && xturn > 6 && xturn < 69 && obimpr[ZSEED] > 4000)
  169.     speak(341);
  170.     /* vine describe   */
  171.     if (loc == 74 && obimpr[ZVINE] == 9) {
  172.     speak(339);
  173.     obimpr[ZVINE] = 8201;
  174.     } else if (loc == 74 && obimpr[ZVINE] == 8201)
  175.     speak(259);
  176. }
  177.  
  178. vinven()
  179. /* "inventory"  */
  180. {
  181.     int             carryn, wearn, i, k;
  182.  
  183.     carryn = 0;
  184.     wearn = 0;
  185.     if (wirelc[5] == 1000)
  186.     carryn = 1;
  187.     for (i = 1; i <= MOVMAX; i++) {
  188.     if (obloc[i] == 1000)
  189.         carryn = 1;
  190.     if (obloc[i] == 3000)
  191.         wearn = 1;
  192.     }
  193.     if (carryn == 1) {
  194.     speak(62);
  195.         xindnt += 2;
  196.     if (wirelc[5] == 1000)
  197.         speak(256);
  198.     for (k = 1; k <= MOVMAX; k++) {
  199.         if (obloc[k] != 1000)
  200.         continue;
  201.         speak(odistb[k]);
  202.         if (obpprp[k] / 2048 != 0)
  203.         xcontn(k);
  204.     }
  205.         xindnt -= 2;
  206.     }
  207.     if (wearn == 1) {
  208.     speak(63);
  209.         xindnt += 2;
  210.     for (k = 1; k <= MOVMAX; k++) {
  211.         if (obloc[k] != 3000)
  212.         continue;
  213.         speak(odistb[k]);
  214.         if (obpprp[k] / 2048 != 0)
  215.         xcontn(k);
  216.     }
  217.         xindnt -= 2;
  218.     }
  219.     if (carryn == 0 && wearn == 0)
  220.     speak(64);
  221.     nonext = 1;
  222. }
  223.  
  224. xcontn(k)                             /* RECURSIVE FUNCTION */
  225.     int             k;
  226. {
  227.     int             p, empty, k1;
  228.     /*
  229.      * list contents of a container 
  230.      * calls itself recursively to list things inside other containers
  231.      */
  232.  
  233.  
  234.            /* RECURSIVE FUNCTION */
  235.     if (k == LFUNNE || k == MFUNNE || k == RFUNNE)
  236.     return;
  237.     p = obimpr[k];
  238.     if ((p & 2) == 0 || (obpprp[k] & 128) == 0) {
  239.     empty = 1;
  240.     for (k1 = 1; k1 <= MOVMAX; k1++)
  241.         if (obloc[k1] == k + 2000)
  242.         empty = 0;
  243.     if (empty) {
  244.         xindnt += 2;
  245.         speak(odistb[k] + ((p / 512) % 8));
  246.         xindnt -= 2;
  247.     } else {
  248.         xindnt += 2;
  249.         speak(odistb[k] + ((p / 512) % 8) + 1);
  250.         xindnt += 2;
  251.         for (k1 = 1; k1 <= MOVMAX; k1++) {
  252.         if (obloc[k1] == k + 2000) {
  253.             speak(odistb[k1]);
  254.                  if (obpprp[k1] / 2048 != 0)
  255.                 xcontn(k1);
  256.                 }
  257.         }
  258.         xindnt -= 4;
  259.     }
  260.     } else if ((p & 2) != 0 && (obpprp[k] & 128) != 0 && prepdo == IN)
  261.     speak(386);
  262. }
  263.  
  264. dbg()
  265. {
  266.     char tmpstrq[80];
  267.     
  268.     if(debugflg == 0) return;
  269.     debugflg = 2;
  270.     printf(" loc is %5d \n", loc);
  271.     printf(" enter new loc ");
  272.     gets(tmpstrq);
  273.     sscanf(tmpstrq,"%d", &loc);
  274. }
  275.  
  276. scorng()
  277. {
  278.     int             result, i, q, v, l, n, plce, xplc;
  279.     result = 0;
  280.     if (loc >= 153)
  281.     return (0);
  282.     result = (diesc - 3) * 2;
  283.     if (result < 0)
  284.     result = 0;
  285.     if (cactsc == 1 || cactsc == 2)
  286.     result += 2;
  287.     if (cactsc == 3)
  288.     result += 4;
  289.     if ((eastsc & 1) != 0)
  290.     result += 2;
  291.     if ((eastsc & 2) != 0)
  292.     result += 2;
  293.     if ((eastsc & 4) != 0)
  294.     result += 2;
  295.     if(debugflg == 2) 
  296.         printf(" east+cact %5d out of 10\n",result);
  297.     for (i = 1; i <= MOVMAX; i++) {
  298.     q = obw4[i];
  299.     v = q / 4096;
  300.     l = q - v * 4096;
  301.     if (v == 0)
  302.         continue;
  303.         n = 0;
  304.     itsher(i, &plce);
  305.     if (i == GDISC) {
  306.         if (plce != 0 && rvtim == 2)
  307.         n = v;
  308.     } else if (l >= 4000 && l - 4000 != obloc[i])
  309.         n = v;
  310.     else if (l == 3000 && obloc[i] == 3000)
  311.         n = v;
  312.     else if (l == 1000 && (plce == 1 || plce == 3))
  313.         n = v;
  314.     else if (l == 3000 && (plce == 1 || plce == 3))
  315.         n = v / 2;
  316.     else if (l < 1000 && l == obloc[i])
  317.         n = v;
  318.     else if (l > 2000 && l < 3000 && obloc[i] == l) {
  319.         itsher((l - 2000), &xplc);
  320.         if (xplc > 0 && xplc <= 3)
  321.         n = v;
  322.     }
  323.         result += n;
  324.         if(debugflg == 2)printf("obj %5d %5d points out of %5d\n",i,n,v);
  325.     }
  326.     if (deadf)
  327.     result -= 5;
  328.     if (result < 0)
  329.     result = 0;
  330.     result *= 5;
  331.     return (result);
  332. }
  333.  
  334. getrob(don, doa)
  335.     int             don, doa;
  336. {
  337.     int             result, i;
  338.     /*
  339.      * search table for object return object number if found and unambiguous
  340.      * return 0 if not found return -1 if ambiguous  
  341.      */
  342.  
  343.     for (i = 1; i <= OBJMAX; i++) {
  344.     if (don != obnoun[i])
  345.         continue;
  346.     if ((doa == abs(obadjv[i])) || (doa == 0 && obadjv[i] < 0))
  347.         return (i);
  348.     else if (doa == 0 && obadjv[i] > 0)
  349.         result = -1;
  350.     else
  351.         result = 0;
  352.     }
  353.     return (result);
  354. }
  355.  
  356.     static  char    sstring[] =
  357.     "Your score is     out of a total of     in      turns.";
  358.     static  int     breakp[] = {0, 35, 70, 90, 130, 170, 210, 260, 330,
  359.                 380, 450, 900};
  360. scorpt(scor, mxsc)
  361.     int             scor, mxsc;
  362. {
  363.     char            cnum[4];
  364.     int             i;
  365.  
  366.     numcvt(scor, cnum);
  367.     sstring[14] = cnum[1];
  368.     sstring[15] = cnum[2];
  369.     sstring[16] = cnum[3];
  370.     numcvt(mxsc, cnum);
  371.     sstring[36] = cnum[1];
  372.     sstring[37] = cnum[2];
  373.     sstring[38] = cnum[3];
  374.     numcvt(turns, cnum);
  375.     sstring[43] = cnum[0];
  376.     sstring[44] = cnum[1];
  377.     sstring[45] = cnum[2];
  378.     sstring[46] = cnum[3];
  379.     linout(sstring, 54);
  380.     for (i = 0; i < 10; i++) {
  381.     if (scor >= breakp[i] && scor < breakp[i + 1])
  382.         break;
  383.     }
  384.     speak(481 + i);
  385.  
  386. }
  387.  
  388. numcvt(num, cnum)
  389.     int             num;
  390.     char           *cnum;
  391. {
  392.     int             lx, m;
  393.  
  394.     m = num / 1000;
  395.     lx = (m) ? '0' + m : ' ';
  396.     *cnum++ = lx;
  397.     m = (num / 100) % 10;
  398.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  399.     *cnum++ = lx;
  400.     m = (num / 10) % 10;
  401.     lx = (m == 0 && lx == ' ') ? ' ' : '0' + m;
  402.     *cnum++ = lx;
  403.     m = num % 10;
  404.     *cnum = '0' + m;
  405. }
  406.  
  407. robdsc()
  408. {
  409.     int             rempty, lempty, k;
  410.  
  411.     if (obloc[ZROBOT] >= 90 && obloc[ZROBOT] <= 95)
  412.     speak(gtext[1] + obloc[ZROBOT]);
  413.     else
  414.     speak(226 + obloc[ZROBOT]);
  415.     rempty = 1;
  416.     lempty = 1;
  417.     for (k = 1; k <= MOVMAX; k++) {
  418.     if (obloc[k] == 2000 + ZROBOT)
  419.         rempty = 0;
  420.     if (obloc[k] == obloc[ZROBOT] && k != ZROBOT)
  421.         lempty = 0;
  422.     }
  423.     if (rempty == 0) {
  424.     speak(odistb[ZROBOT] + 5);
  425.     for (k = 1; k <= MOVMAX; k++) {
  426.         xindnt += 2;
  427.         if (obloc[k] == 2000 + ZROBOT)
  428.         speak(odistb[k]);
  429.         xindnt -= 2;
  430.     }
  431.     }
  432.     if (lempty == 0) {
  433.     speak(350);
  434.     for (k = 1; k <= MOVMAX; k++) {
  435.         xindnt += 2;
  436.         if (k != ZROBOT && obloc[k] == obloc[ZROBOT])
  437.         speak(odistb[k]);
  438.         xindnt -= 2;
  439.     }
  440.     }
  441.     if (obloc[ZROBOT] == 90 && (obloc[ZORCHI] == 2000 + ZROBOT
  442.                 || obloc[ZFLYTR] == 2000 + ZROBOT))
  443.     speak(353);
  444. }
  445.  
  446.  
  447. endsl()
  448. {
  449. #ifdef AMIGA
  450.     ttclose();       /* dummy routine to maybe clear screen? */
  451. #endif
  452. }
  453.  
  454.  
  455. vdead()
  456. {
  457.     int             i;
  458.     /*
  459.      * "you're dead,fred" it is incumbent on the calling routine to get to
  460.      * where the body is supposed to lie, and to set oldloc and oldlc2 to
  461.      * ,usually, 0 this routine sets deadf to .true. and drops all his
  462.      * possessions where he is now 
  463.      */
  464.  
  465.     eattim = 0;
  466.     rdietm = 0;
  467.     deadf = 1;
  468.     for (i = 1; i <= MOVMAX; i++)
  469.     if (obloc[i] == 1000 || obloc[i] == 3000)
  470.         obloc[i] = loc;
  471.     if (loc < 153)
  472.     speak(55);
  473.     else
  474.     speak(552);
  475.     nonext = 1;
  476.     eolflg = 1;
  477.     spcloc = 0;
  478.     for (i = 0; i < 6; i++)
  479.     if (wirelc[i] == 1000)
  480.         wirelc[i] = loc;
  481.     if (wirelc[0] != obloc[ZWIRE])
  482.     return;
  483.     for (i = 0; i < 6; i++)
  484.     wirelc[i] = 0;
  485.     diesc += 1;
  486. }
  487.  
  488. itsher(objt, plce)
  489.     int             objt;
  490.     int            *plce;
  491. {
  492.     int             n1;
  493.     /*
  494.      * this subroutine tells if an object is either: being carried     plce=1
  495.      * being worn        plce=2 inside something being carried,and not hidden
  496.      * from view (3) at "loc" and not hidden  (4) inside something at loc (5) 
  497.      */
  498.  
  499.     *plce = 0;
  500.     if (objt <= MOVMAX) {
  501.     if (obloc[objt] == 1000)
  502.         *plce = 1;
  503.     else if (obloc[objt] == 3000)
  504.         *plce = 2;
  505.     else if (obloc[objt] == loc && (obimpr[objt] & 1) == 1)
  506.         *plce = 4;
  507.     else if (obloc[objt] > 2000 && obloc[objt] < 3000) {
  508.         n1 = obloc[objt] - 2000;
  509.         if (n1 <= MOVMAX) {
  510.         if ((obloc[n1] == 1000 || obloc[n1] == 3000)
  511.             && (obimpr[n1] & 2) == 0)
  512.             *plce = 3;
  513.         else if (obloc[n1] == loc && ((obimpr[n1] & 1) == 1)
  514.              && ((obimpr[n1] & 2) == 0))
  515.             *plce = 5;
  516.         else;
  517.         } else if ((obw3[n1] == loc || obw4[n1] == loc) &&
  518.                ((obimpr[n1] & 1) == 1) && ((obimpr[n1] & 2) == 0))
  519.         *plce = 5;
  520.         else;
  521.     } else;
  522.     } else if ((obw3[objt] == loc || obw4[objt] == loc) &&
  523.            ((obimpr[objt] & 1) == 1))
  524.     *plce = 4;
  525. }
  526.  
  527. burden(ncarrd, nweigh, kcarrd, kweigh)
  528.     int            *ncarrd, *nweigh, *kcarrd, *kweigh;
  529. {
  530.     int             i;
  531.     /*
  532.      * calculate weight and number of objects on adventurer and in knapsack  
  533.      */
  534.  
  535.  
  536.     *ncarrd = 0;
  537.     *nweigh = 0;
  538.     for (i = 1; i <= MOVMAX; i++) {
  539.     if (obloc[i] != 1000)
  540.         continue;
  541.     *ncarrd += 1;
  542.     *nweigh += obw3[i] / 256;
  543.     }
  544.     *kcarrd = 0;
  545.     *kweigh = 0;
  546.     for (i = 1; i <= MOVMAX; i++) {
  547.     if (i == ZKNAPS || obloc[i] != (2000 + ZKNAPS))
  548.         continue;
  549.     *kcarrd += 1;
  550.     *kweigh += obw3[i] / 256;
  551.     }
  552. }
  553.  
  554. getobj(don, doa)
  555.     int             don, doa;
  556. {
  557.     /*
  558.      * search table for object return object number if found and unambiguous
  559.      * return 0 if not found return -1 if ambiguous  
  560.      */
  561.  
  562.     int             result, i, g1, g2, ggg, ddd, sum;
  563.     int             aplce, bplce, cplce, dplce, fplce, gplce, mplce, nplce, oplce, pplce;
  564.     int             splce, tplce;
  565.     result = 0;
  566.     for (i = 1; i <= OBJMAX; i++) {
  567.  
  568.     if (don != obnoun[i])
  569.         continue;
  570.     if ((doa == abs(obadjv[i]) && doa != BEAUTI && doa !=
  571.          VENDIN) || (doa == 0 && obadjv[i] < 0)) {
  572.         result = i;
  573.         return (result);
  574.     } else if ((doa == 0 && obadjv[i] > 0) || (doa == VENDIN &&
  575.              don == MACHIN) || (doa == BEAUTI && don == BIRD)) {
  576.         if (don == FISH) {
  577.         if (obloc[CFISH] != 0)
  578.             result = CFISH;
  579.         else
  580.             result = DFISH;
  581.         } else if (don == PANTS) {
  582.         itsher(RPANT, &g1);
  583.         itsher(LPANT, &g2);
  584.         if (g1 != 0 && g2 == 0)
  585.             result = RPANT;
  586.         else if (g1 == 0 && g2 != 0)
  587.             result = LPANT;
  588.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  589.              wrdnum[0] == REMOVE) {
  590.             if (g1 == 2)
  591.             result = RPANT;
  592.             else
  593.             result = LPANT;
  594.         } else if (wrdnum[0] == DROP)
  595.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  596.             result = RPANT;
  597.         if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  598.             result = LPANT;
  599.         else
  600.             result = -1;
  601.         } else if (don == SHIRT) {
  602.         itsher(RSHIRT, &g1);
  603.         itsher(GSHIRT, &g2);
  604.         if (g1 != 0 && g2 == 0)
  605.             result = RSHIRT;
  606.         else if (g1 == 0 && g2 != 0)
  607.             result = GSHIRT;
  608.         else if ((wrdnum[0] == TAKE && prepdo == OFF) ||
  609.              wrdnum[0] == REMOVE) {
  610.             if (g1 == 2)
  611.             result = RSHIRT;
  612.             else
  613.             result = GSHIRT;
  614.         } else if (wrdnum[0] == DROP) {
  615.             if (((g1 == 1) || (g1 == 3)) && g2 != 1 && g2 != 3)
  616.             result = RSHIRT;
  617.             if (((g2 == 1) || (g2 == 3)) && g1 != 1 && g1 != 3)
  618.             result = GSHIRT;
  619.         } else
  620.             result = -1;
  621.         } else if (don == DOOR) {
  622.         if (loc == 41 || loc == 135)
  623.             result = MDOOR;
  624.         else if (loc == 85 || loc == 136)
  625.             result = GDOOR;
  626.         else if (loc == 47 || loc == 51)
  627.             result = RDOOR;
  628.         else if (loc == 165 || loc == 166)
  629.             result = ODOOR;
  630.         else if (loc == 173)
  631.             result = PDOOR;
  632.         else if (loc == 175)
  633.             result = BDOOR;
  634.         else
  635.             result = -1;
  636.         } else if (don == CARTRI) {
  637.         itsher(ZCART, &tplce);
  638.         itsher(CCART, &cplce);
  639.         if (tplce > 0 && cplce <= 0)
  640.             result = ZCART;
  641.         else if (tplce <= 0 && cplce > 0)
  642.             result = CCART;
  643.         else
  644.             result = -1;
  645.         } else if (don == PHOTOG) {
  646.         itsher(PPHOTO, &pplce);
  647.         itsher(MPHOTO, &mplce);
  648.         itsher(OPHOTO, &oplce);
  649.         itsher(APHOTO, &aplce);
  650.         itsher(FPHOTO, &fplce);
  651.         pplce = (pplce < 1) ? pplce : 1;
  652.         mplce = (mplce < 1) ? mplce : 1;
  653.         oplce = (oplce < 1) ? oplce : 1;
  654.         aplce = (aplce < 1) ? aplce : 1;
  655.         fplce = (fplce < 1) ? fplce : 1;
  656.         sum = pplce + mplce + oplce + aplce + fplce;
  657.         {
  658.             if (sum == 0)
  659.             result = 0;
  660.             else if (sum > 1)
  661.             result = -1;
  662.             else {
  663.             if (pplce != 0)
  664.                 result = PPHOTO;
  665.             if (mplce != 0)
  666.                 result = MPHOTO;
  667.             if (oplce != 0)
  668.                 result = OPHOTO;
  669.             if (aplce != 0)
  670.                 result = APHOTO;
  671.             if (fplce != 0)
  672.                 result = FPHOTO;
  673.             }
  674.         }
  675.         } else if (don == BIRD) {
  676.         if (loc == 65 || loc == 66)
  677.             result = RBIRD;
  678.         else if (loc == 78 || loc == 79)
  679.             result = XBIRD;
  680.         else if (loc == 77 || loc == 80)
  681.             result = YBIRD;
  682.         else if (loc == 75 || loc == 76)
  683.             result = ZBIRD;
  684.         else
  685.             result = 0;
  686.         } else if (don == BUTTON) {
  687.         if (loc == 146 || loc == 134)
  688.             result = -1;
  689.         else if (loc == 143)
  690.             result = RDBUTT;
  691.         else if (loc == 169)
  692.             result = GBUTTO;
  693.         else
  694.             result = 0;
  695.         } else if (don == CABLE || don == DISC) {
  696.         if (don == CABLE) {
  697.             ddd = DCABLE;
  698.             ggg = GCABLE;
  699.         } else {
  700.             ddd = BDISC;
  701.             ggg = GDISC;
  702.         }
  703.         itsher(ddd, &dplce);
  704.         itsher(ggg, &gplce);
  705.         if (dplce == 0 && gplce == 0)
  706.             result = 0;
  707.         else {
  708.             if (wrdnum[0] == DROP) {
  709.             if ((dplce == 1 || dplce == 3) && (gplce != 1 
  710.                                                                  && gplce != 3))
  711.                 result = ddd;
  712.             else if ((gplce == 1 || gplce == 3) && 
  713.                                                      (dplce != 1 && dplce != 3))
  714.                 result = ggg;
  715.             else
  716.                 result = -1;
  717.             } else if (wrdnum[0] == TAKE) {
  718.             if ((dplce == 4 || dplce == 5) && (gplce != 4 
  719.                                                                  && gplce != 5))
  720.                 result = ddd;
  721.             else if ((gplce == 4 || gplce == 5) &&
  722.                                                      (dplce != 4 && dplce != 5))
  723.                 result = ggg;
  724.             else
  725.                 result = -1;
  726.             } else {
  727.             if (gplce == 0 && dplce != 0)
  728.                 result = ddd;
  729.             else if (dplce == 0 && gplce != 0)
  730.                 result = ggg;
  731.             else
  732.                 result = -1;
  733.             }
  734.         }
  735.         } else if (don == MACHIN) {
  736.         if (loc == 153)
  737.             result = PMACH;
  738.         else if (loc == 156)
  739.             result = TMACH;
  740.         else if (loc == 158)
  741.             result = NMACH;
  742.         else if (loc == 160)
  743.             result = SMACH;
  744.         else if (loc == 162)
  745.             result = MMACH;
  746.         } else if (don == SLOT) {
  747.         if (loc == 146)
  748.             result = RSLOT;
  749.         else if (loc == 156)
  750.             result = TSLOT;
  751.         else if (loc == 158)
  752.             result = NSLOT;
  753.         else if (loc == 160)
  754.             result = SSLOT;
  755.         else if (loc == 162)
  756.             result = MSLOT;
  757.         } else if (don == COIN) {
  758.         if (loc < 153)
  759.             result = SCOIN;
  760.         else {
  761.             itsher(SCOIN, &splce);
  762.             itsher(BCOIN, &bplce);
  763.             itsher(CCOIN, &cplce);
  764.             itsher(NCOIN, &nplce);
  765.             itsher(PCOIN, &pplce);
  766.             pplce = (pplce < 1) ? pplce : 1;
  767.             nplce = (nplce < 1) ? nplce : 1;
  768.             cplce = (cplce < 1) ? cplce : 1;
  769.             bplce = (bplce < 1) ? bplce : 1;
  770.             splce = (splce < 1) ? splce : 1;
  771.             sum = pplce + nplce + cplce + bplce + splce;
  772.             if (sum == 0)
  773.             result = 0;
  774.             else if (sum > 1)
  775.             result = -1;
  776.             else {
  777.             if (splce != 0)
  778.                 result = SCOIN;
  779.             if (bplce != 0)
  780.                 result = BCOIN;
  781.             if (cplce != 0)
  782.                 result = CCOIN;
  783.             if (nplce != 0)
  784.                 result = NCOIN;
  785.             if (pplce != 0)
  786.                 result = PCOIN;
  787.             }
  788.         }
  789.         } else
  790.         result = -1;
  791.         return (result);
  792.     }
  793.     }
  794.     return (result);
  795. }
  796.     static  char    strng1[] = "    I can't do that to item    on your list.";
  797.     static  char    strng2[] = "    Item number    on your list is ambiguous";
  798.  
  799. cnvobj()
  800. {
  801.     char            cnum[4];
  802.     int             result, many, i, k, n, p, z;
  803.  
  804.     /*
  805.      * this routine searches the list of objects and compares with the list
  806.      * of d.o.'s if an object exists and is unambiguous it's entry in dobjs
  807.      * is replaced by its object number otherwise its entry in dobjs is set
  808.      * to zero the entries in dobsj are then squeezed up if the result was
  809.      * totally unambiguous cnvobj is .true. 
  810.      */
  811.  
  812.     result = 1;
  813.     n = 0;
  814.     if (allflg)
  815.     n = 1;
  816.     many = 0;
  817.     if ((butflg && dobjs[2] != 0) || ((!butflg) &&
  818.                       dobjs[1] != 0))
  819.     many = 1;
  820.     k = 0;
  821.     z = -1;
  822.     for (i = n; i < 12; i++) {
  823.     k += 1;
  824.     if (dobjs[i] == 0)
  825.         break;
  826.     p = getobj(dobjs[i], doadjs[i]);
  827.     if (p > 0) {
  828.         z += 1;
  829.         dobjs[z] = p;
  830.     } else if (p == 0) {
  831.         if (many == 1) {
  832.         numcvt(k, cnum);
  833.         strng1[28] = cnum[2];
  834.         strng1[29] = cnum[3];
  835.         linout(strng1, 44);
  836.         } else
  837.         speak(422);
  838.     } else {
  839.         result = 0;
  840.         if (many == 1) {
  841.         numcvt(k, cnum);
  842.         strng2[16] = cnum[2];
  843.         strng2[17] = cnum[3];
  844.         linout(strng2, 44);
  845.         } else
  846.         speak(70);
  847.         speak(250);
  848.     }
  849.     }
  850.     while (++z < 30)
  851.     dobjs[z] = 0;
  852.     return (result);
  853. }
  854.  
  855. getall()
  856. {
  857.  
  858.     int             temp[30], i, k, d, m;
  859.     /*
  860.      * routine to get "all" or "all but" objects it only works on moveable
  861.      * objects because the only verbs which call it work only on those
  862.      * objects (drop,take, put) 
  863.      */
  864.  
  865.     for (i = 0; i < 30; i++) {
  866.     temp[i] = dobjs[i];
  867.     dobjs[i] = 0;
  868.     }
  869.     k = 0;
  870.     for (i = 1; i <= MOVMAX; i++) {
  871.     itsher(i, &d);
  872.     if (d == 0)
  873.         continue;
  874.     for (m = 0; m < 30; m++)
  875.         if (temp[m] == i)
  876.         goto endloop;
  877.     if (k == 29) {
  878.         speak(106);
  879.         return;
  880.     }
  881.     dobjs[k++] = i;
  882. endloop:
  883.     ;
  884.     }
  885. }
  886.  
  887.  
  888. rdinit()
  889. {
  890.     long            t;
  891.     long            tloc;
  892.     long            time();
  893.     int             ti;
  894.     t = time(&tloc);
  895.     ti =( (int) t) & 32767;
  896.     srand(ti);
  897. }
  898.  
  899. qrand()
  900. {
  901.     return ((rand() & 16383) / 4);
  902. }
  903.  
  904.  
  905. pct(q)
  906.     int             q;
  907. {
  908.     int             j;
  909.  
  910.     j = rand();
  911.     return ((q * 327) > (j & 32767));
  912. }
  913.  
  914. yesx(spk)
  915.     int             spk;
  916. {
  917.     char            ans[90];
  918.     /* ask question, and wait for reply from him */
  919.  
  920.  
  921.     speak(spk);
  922.     more = 0;
  923.     while (1) {
  924.     linout("?", 2001);
  925.     gets(ans);
  926.     more = 1;
  927.     if (strcmp(ans, "Y") == 0 || strcmp(ans, "YES") == 0
  928.         || strcmp(ans, "y") == 0 || strcmp(ans, "yes") == 0)
  929.         return (1);
  930.     else if (strcmp(ans, "N") == 0 || strcmp(ans, "NO") == 0
  931.          || strcmp(ans, "n") == 0 || strcmp(ans, "no") == 0)
  932.         return (0);
  933.     else
  934.         speak(102);
  935.     }
  936. }
  937.  
  938. getln()
  939. {
  940.     /* write a prompt, then read a line from the terminal */
  941.  
  942.     int             i, lastpos;
  943.     linout("> ", 7001);
  944.  
  945.     gets(inbuf);
  946.     eolflg = 0;
  947.     lastpos = strlen(inbuf);
  948.     lastpos = (lastpos > 78) ? 78 : lastpos;
  949.     for (i = lastpos; i < 83; i++)
  950.     inbuf[i] = '.';
  951.     more = 1;
  952.     inbuf[127] = (char)lastpos;
  953. }
  954.  
  955.  
  956. carerr(x, z)
  957.     int             x, z;
  958. {
  959.     /*
  960.      * this nifty routine put a caret on the terminal at the indicated
  961.      * position of a line and then outputs a message  
  962.      */
  963.     /* if not the first sentence on a line, rewrite line.  */
  964.  
  965.     if (clause != 1) {
  966.     linout(" ", 1001);
  967.     linout(inbuf, inbuf[127]);
  968.     }
  969.     if (x > 0) {
  970.     xindnt = x;
  971.     linout("^", 1);
  972.     xindnt = 0;
  973.     } else {
  974.     if (clause != 1) {
  975.         xindnt = lptr - 1;
  976.         linout("*", 1);
  977.         xindnt = 0;
  978.         speak(423);
  979.     }
  980.     }
  981.     speak(z);
  982. }
  983.  
  984. linout(ustring, num)
  985.     char           *ustring;
  986.     int             num;
  987.  
  988. {
  989.     int             num1, i;
  990.     char            buff[80];
  991.     char           *cptr;
  992.  
  993.     cptr = buff;
  994.     num1 = num % 1000;
  995.     for (i = 0; i < xindnt; i++)
  996.     *cptr++ = ' ';
  997.  
  998.     for (i = 0; i < num1; i++)
  999.     *cptr++ = *ustring++;
  1000.  
  1001.     *cptr++ = '\0';
  1002.     if (num < 1000) {
  1003.         if(more == 19 && nomor == 0) {
  1004.             i = strlen(buff);
  1005.             for( ; i < 73; i++)
  1006.                buff[i] = ' '; 
  1007.             strcpy(&buff[73],"MORE");
  1008.             printf("%1s", buff);
  1009.             gets(buff);
  1010.             more = 0;
  1011.         }
  1012.         else {
  1013.             printf("%1s\n", buff);
  1014.             more += 1;
  1015.         }
  1016.     }
  1017.     else
  1018.     printf("%1s", buff);
  1019. }
  1020.  
  1021.  
  1022. vsuspe(inout)
  1023.     int             inout;
  1024. {
  1025.     short            sbuffer[256];
  1026.     int             result, filedes, i, iret;
  1027.     short           *sbptr, *iptr;
  1028.     result = 0;
  1029.  
  1030.     if (inout != 1) {
  1031.     /* "suspend" or "save"  */
  1032.  
  1033.     filedes = creat(filenm, 0600);
  1034.     if (filedes == -1) {
  1035.         linout("I failed to create your save file.", 34);
  1036.         return (result);
  1037.     }
  1038.     sbptr = sbuffer;
  1039.     *sbptr++ = horflg;
  1040.     for (i = 0; i < 6; i++)
  1041.         *sbptr++ = wirelc[i];
  1042.     *sbptr++ = turns;
  1043.     *sbptr++ = loc;
  1044.     *sbptr++ = oldloc;
  1045.     *sbptr++ = oldlc2;
  1046.     *sbptr++ = brfflg;
  1047.     *sbptr++ = deadf;
  1048.     *sbptr++ = dirty;
  1049.     *sbptr++ = nonext;
  1050.     *sbptr++ = spcloc;
  1051.     *sbptr++ = fshlif;
  1052.     *sbptr++ = noshoe;
  1053.     *sbptr++ = daytim;
  1054.     *sbptr++ = martim;
  1055.     for (i = 0; i < 9; i++)
  1056.         *sbptr++ = marflg[i];
  1057.     *sbptr++ = oextim;
  1058.     *sbptr++ = rdietm;
  1059.     *sbptr++ = rvtim;
  1060.     *sbptr++ = gvtim;
  1061.     *sbptr++ = eattim;
  1062.     *sbptr++ = easttm;
  1063.     *sbptr++ = filmtm;
  1064.     *sbptr++ = screef;
  1065.     *sbptr++ = eastsc;
  1066.     *sbptr++ = cactsc;
  1067.     *sbptr++ = diesc;
  1068.     *sbptr++ = filmst;
  1069.     *sbptr++ = machst;
  1070.     *sbptr++ = dial1;
  1071.     *sbptr++ = dial2;
  1072.     *sbptr++ = dial1x;
  1073.     *sbptr++ = dial2x;
  1074.     *sbptr++ = bonus;
  1075.     *sbptr++ = jackpo;
  1076.     *sbptr++ = lpill;
  1077.     *sbptr++ = pbstat;
  1078.     *sbptr++ = decset;
  1079.     *sbptr++ = raset;
  1080.     *sbptr++ = dcombi;
  1081.     *sbptr++ = chaset;
  1082.     *sbptr++ = guardl;
  1083.         *sbptr++ = fimage;
  1084.     write(filedes, sbuffer, 64*sizeof(short));
  1085.     sbptr = sbuffer;
  1086.     iptr = locdat;
  1087.     for (i = 0; i <= LOCNUM; i++)
  1088.         *sbptr++ = *iptr++;
  1089.     write(filedes, sbuffer, 256*sizeof(short));
  1090.     sbptr = sbuffer;
  1091.     iptr = obimpr;
  1092.     for (i = 0; i <= OBJMAX; i++)
  1093.         *sbptr++ = *iptr++;
  1094.     write(filedes, sbuffer, 256*sizeof(short));
  1095.     sbptr = sbuffer;
  1096.     iptr = obloc;
  1097.     for (i = 0; i <= OBJMAX; i++)
  1098.         *sbptr++ = *iptr++;
  1099.     write(filedes, sbuffer, 256*sizeof(short));
  1100.     close(filedes);
  1101.     return (result);
  1102.     } else {
  1103.     /* "restore"    */
  1104.  
  1105.     filedes = open(filenm, 0);
  1106.     if (filedes == -1)
  1107.         goto lab1;
  1108.     iret = read(filedes, sbuffer, 64*sizeof(short));
  1109.     if (iret != 64*sizeof(short))
  1110.         goto lab1;
  1111.     sbptr = sbuffer;
  1112.     horflg = *sbptr++;
  1113.     for (i = 0; i < 6; i++)
  1114.         wirelc[i] = *sbptr++;
  1115.     turns = *sbptr++;
  1116.     loc = *sbptr++;
  1117.     oldloc = *sbptr++;
  1118.     oldlc2 = *sbptr++;
  1119.     brfflg = *sbptr++;
  1120.     deadf = *sbptr++;
  1121.     dirty = *sbptr++;
  1122.     nonext = *sbptr++;
  1123.     spcloc = *sbptr++;
  1124.     fshlif = *sbptr++;
  1125.     noshoe = *sbptr++;
  1126.     daytim = *sbptr++;
  1127.     martim = *sbptr++;
  1128.     for (i = 0; i < 9; i++)
  1129.         marflg[i] = *sbptr++;
  1130.     oextim = *sbptr++;
  1131.     rdietm = *sbptr++;
  1132.     rvtim = *sbptr++;
  1133.     gvtim = *sbptr++;
  1134.     eattim = *sbptr++;
  1135.     easttm = *sbptr++;
  1136.     filmtm = *sbptr++;
  1137.     screef = *sbptr++;
  1138.     eastsc = *sbptr++;
  1139.     cactsc = *sbptr++;
  1140.     diesc = *sbptr++;
  1141.     filmst = *sbptr++;
  1142.     machst = *sbptr++;
  1143.     dial1 = *sbptr++;
  1144.     dial2 = *sbptr++;
  1145.     dial1x = *sbptr++;
  1146.     dial2x = *sbptr++;
  1147.     bonus = *sbptr++;
  1148.     jackpo = *sbptr++;
  1149.     lpill = *sbptr++;
  1150.     pbstat = *sbptr++;
  1151.     decset = *sbptr++;
  1152.     raset = *sbptr++;
  1153.     dcombi = *sbptr++;
  1154.     chaset = *sbptr++;
  1155.     guardl = *sbptr++;
  1156.         fimage = *sbptr++;
  1157.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1158.     if (iret != 256*sizeof(short))
  1159.         goto lab1;
  1160.     sbptr = sbuffer;
  1161.     iptr = locdat;
  1162.     for (i = 0; i <= LOCNUM; i++)
  1163.         *iptr++ = *sbptr++;
  1164.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1165.     if (iret != 256*sizeof(short))
  1166.         goto lab1;
  1167.     sbptr = sbuffer;
  1168.     iptr = obimpr;
  1169.     for (i = 0; i <= OBJMAX; i++)
  1170.         *iptr++ = *sbptr++;
  1171.     iret = read(filedes, sbuffer, 256*sizeof(short));
  1172.     if (iret != 256*sizeof(short))
  1173.         goto lab1;
  1174.     sbptr = sbuffer;
  1175.     iptr = obloc;
  1176.     for (i = 0; i <= OBJMAX; i++)
  1177.         *iptr++ = *sbptr++;
  1178.         close(filedes);
  1179.     result = 1;
  1180.     chaser = 0;
  1181.     linout(" ", 1);
  1182.     return (result);
  1183.     }
  1184. lab1:
  1185.     linout("Restore failed.", 15);
  1186.     return (result);
  1187. }
  1188.